<template>
    <div>
        <h1>病房列表</h1>
        <a href="/badd">病房新增</a>
        <br>
        <a href="/login">管理员登录</a>
        <br>
        <a href="/">主页</a>
        <br>
        病房号<input type="text" v-model="list.roomfh">
        科室:<select v-model="list.rid">
                    <option value="0">请选择</option>
                    <option v-for="x in xl" :value="x.rid">{{x.rname}}</option>
                </select>
        <input type="button" value="查询" @click="cx">
            <table class="table">
                <thead>
                    <tr>
                        <td>病房号</td>
                        <td>所属科室</td>
                        <td>床位总数量</td>
                        <td>状态</td>
                        <td>空闲床数量</td>
                        <td>创建日期</td>
                        <td>默认状态</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="d in data">
                        <td>{{d.rfh}}</td>
                        <td>{{d.rname}}</td>
                        <td>{{d.roomcw}}</td>
                        <td>{{d.roomState==1?"维修":"启用"}}</td>
                        <td>{{d.roomkx}}</td>
                        <td>{{moment(d.roomtime).format("yyyy-MM-DD HH:mm:ss")}}</td>
                        <td>{{d.roomzt==1?"未满":"已满"}}</td>
                        <td><input type="button" :value="d.roomState==1?'启用':'维修'" @click="zt(d.roomId)"></td>
                    </tr>
                </tbody>
            </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import moment from 'moment'
const router=useRouter();
const route=useRoute();
const data=ref([{
    "roomId": 3,
    "rfh": "1001",
    "rid": 4,
    "roomcw": 4,
    "roomState": 2,
    "roomkx": 3,
    "roomtime": "2025-05-19T12:37:11.8268546",
    "roomzt": 1,
    "rname": "中医科室"
}])
const list=ref({
    roomfh:"",
    rid:0
})
onMounted(() => {
    show()
    xlk()
})
const show=()=>{
    axios.get("/api/Roombf/GetRoombf",{params:list.value}).then(res=>{
        data.value=res.data
    })
}
const cx=()=>{
    show();
    
}
const xl=ref({})
const xlk=()=>{
    axios.get("/api/RoomKs/GetRoomKsBy").then(res=>{
        xl.value=res.data
    })
}
const zt=(val:any)=>{
    if(confirm("确认修改吗")){
        axios.get("/api/Roombf/UpdateRoombf",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("修改成功")
            show()
        }else{
            alert("修改失败")
        }
    })
    }
    
}
</script>

<style scoped>

</style>